﻿@*
    TicketDesk - Attribution notice
    Contributor(s):

         Stephen Redd (stephen@reddnet.net, http://www.reddnet.net)

    This file is distributed under the terms of the Microsoft Public
    License (Ms-PL). See http://opensource.org/licenses/MS-PL
    for the complete terms of use.

    For any distribution that contains code from this file, this notice of
    attribution must remain intact, and a copy of the license must be
    provided to the recipient.
*@

@using System.Configuration
@model TicketDesk.PushNotifications.Model.ApplicationPushNotificationSetting

@section title
{
    Push Notification Settings
}

@section scripts
{
    <script type="text/javascript">
        $(document).ready(function () {
            $('#useCurrentUrlButton').on('click', function () {
                $('#siteRootUrl').val('@ViewBag.CurrentRootUrl');
            });
        });
    </script>
}

<main>
    <div class="container">
        <fieldset>
            <legend class="col-lg-9 col-lg-offset-1 col-sm-12">Push notification settings</legend>
            <div class="col-lg-8 col-lg-offset-2  col-sm-12">
                @{
                    var demoMode = ConfigurationManager.AppSettings["ticketdesk:DemoModeEnabled"] ?? "false";
                    if (demoMode.Equals("true", StringComparison.InvariantCultureIgnoreCase))
                    {
                        <div class="alert alert-warning">
                            <p>TicketDesk is running demo mode. Push notifications are disabled.</p>
                            <p> To turn off demo mode, please change the setting in application configuration.</p>
                        </div>
                    }
                    else
                    {

                        using (Html.BeginForm("Index", "PushNotificationSettings", FormMethod.Post, new { @class = "form-horizontal" }))
                        {

                            @Html.AntiForgeryToken()
                            <div class="panel panel-info">
                                <div class="panel-heading">
                                    <h2 class="panel-title">General settings</h2>
                                </div>
                                <div class="panel-body">
                                    @Html.ValidationSummary(true, "", new { @class = "text-danger" })

                                    @Html.HiddenFor(model => model.ApplicationName)
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.IsEnabled, new { @class = "col-md-4 col-sm-4 control-label" })
                                        <div class="col-md-8 col-sm-8">
                                            <label class="checkbox-inline">
                                                @Html.EditorFor(model => model.IsEnabled)
                                                @Html.PromptFor(model => model.IsEnabled)
                                            </label>
                                            @Html.ValidationMessageFor(model => model.IsEnabled, "", new { @class = "text-danger" })
                                            @Html.DescriptionFor(model => model.IsEnabled, "help-block", "span")
                                            @if (!Model.DeliveryProviderSettings.Any(p => p.IsEnabled) && Model.IsEnabled)
                                            {
                                                <p class="alert alert-danger">At least one provider must be enabled in order for messages to be sent.</p>
                                            }
                                        </div>
                                    </div>


                                    <div class="form-group">
                                        <label for="siteRootUrl" class="col-md-4 col-sm-4 control-label">Site Root Url</label>
                                        <div class="col-md-8 col-sm-8">
                                            <div class="input-group input-group-sm">
                                                <input id="siteRootUrl"
                                                       name="siteRootUrl"
                                                       class="form-control input-sm"
                                                       type="url"
                                                       data-val="true"
                                                       data-val-url="The url is invalid. If you are trying to use localhost for testing, specify the loopback IP address instead (http://127.0.0.1:80)"
                                                       value="@ViewBag.SiteRootUrl"/>
                                                <span class="input-group-btn">
                                                    <button id="useCurrentUrlButton"
                                                            type="button"
                                                            data-toggle="tooltip"
                                                            data-placement="bottom"
                                                            title="Use current root URL" class="btn btn-default btn-sm">
                                                        <i class="fa fa-link"></i>
                                                    </button>
                                                </span>

                                            </div>
                                            <div class="field-validation-valid" data-valmsg-for="siteRootUrl" data-valmsg-replace="true"></div>
                                            <span class="help-block">
                                                This setting is vital to ensure that hyperlinks in emails contain the currect URL to your site.
                                            </span>
                                        </div>
                                    </div>







                                    <div class="form-group">
                                        @Html.LabelFor(model => model.DeliveryIntervalMinutes, new { @class = "col-md-4 col-sm-4  control-label" })
                                        <div class="col-md-8 col-sm-8">
                                            @Html.EditorFor(model => model.DeliveryIntervalMinutes, new { htmlAttributes = new { @class = "form-control input-sm" } })
                                            @Html.ValidationMessageFor(model => model.DeliveryIntervalMinutes, "", new { @class = "text-danger" })
                                            @Html.DescriptionFor(model => model.DeliveryIntervalMinutes, "help-block", "span")
                                        </div>


                                    </div>
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.RetryAttempts, new { @class = "col-md-4 col-sm-4  control-label" })
                                        <div class="col-md-8 col-sm-8">
                                            @Html.EditorFor(model => model.RetryAttempts, new { htmlAttributes = new { @class = "form-control input-sm" } })
                                            @Html.ValidationMessageFor(model => model.RetryAttempts, "", new { @class = "text-danger" })

                                            @Html.DescriptionFor(model => model.RetryAttempts, "help-block", "span")
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.RetryIntervalMinutes, new { @class = "col-md-4 col-sm-4 control-label" })
                                        <div class="col-md-8 col-sm-8">
                                            @Html.EditorFor(model => model.RetryIntervalMinutes, new { htmlAttributes = new { @class = "form-control input-sm" } })
                                            @Html.ValidationMessageFor(model => model.RetryIntervalMinutes, "", new { @class = "text-danger" })

                                            @Html.DescriptionFor(model => model.RetryIntervalMinutes, "help-block", "span")
                                        </div>
                                    </div>

                                </div>
                                <div class="panel-heading">
                                    <h2 class="panel-title">Anti-noise settings</h2>
                                </div>
                                <div class="panel-body ">
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.AntiNoiseSettings.ExcludeSubscriberEvents, new { @class = "col-md-4 col-sm-4 control-label" })
                                        <div class="col-md-8 col-sm-8">
                                            <label class="checkbox-inline">
                                                @Html.EditorFor(model => model.AntiNoiseSettings.ExcludeSubscriberEvents)
                                                @Html.PromptFor(model => model.AntiNoiseSettings.ExcludeSubscriberEvents)
                                            </label>
                                            @Html.ValidationMessageFor(model => model.AntiNoiseSettings.ExcludeSubscriberEvents, "", new { @class = "text-danger" })

                                            @Html.DescriptionFor(model => model.AntiNoiseSettings.ExcludeSubscriberEvents, "help-block", "span")
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.AntiNoiseSettings.IsConsolidationEnabled, new { @class = "col-md-4 col-sm-4 control-label" })
                                        <div class="col-md-8 col-sm-8">
                                            <label class="checkbox-inline">
                                                @Html.EditorFor(model => model.AntiNoiseSettings.IsConsolidationEnabled)
                                                @Html.PromptFor(model => model.AntiNoiseSettings.IsConsolidationEnabled)
                                            </label>
                                            @Html.ValidationMessageFor(model => model.AntiNoiseSettings.IsConsolidationEnabled, "", new { @class = "text-danger" })

                                            @Html.DescriptionFor(model => model.AntiNoiseSettings.IsConsolidationEnabled, "help-block", "span")
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.AntiNoiseSettings.InitialConsolidationDelayMinutes, new { @class = "col-md-4 col-sm-4 control-label" })
                                        <div class="col-md-8 col-sm-8">
                                            @Html.EditorFor(model => model.AntiNoiseSettings.InitialConsolidationDelayMinutes, new { htmlAttributes = new { @class = "form-control input-sm" } })
                                            @Html.ValidationMessageFor(model => model.AntiNoiseSettings.InitialConsolidationDelayMinutes, "", new { @class = "text-danger" })

                                            @Html.DescriptionFor(model => model.AntiNoiseSettings.InitialConsolidationDelayMinutes, "help-block", "span")
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        @Html.LabelFor(model => model.AntiNoiseSettings.MaxConsolidationDelayMinutes, new { @class = "col-md-4 col-sm-4 control-label" })
                                        <div class="col-md-8 col-sm-8">
                                            @Html.EditorFor(model => model.AntiNoiseSettings.MaxConsolidationDelayMinutes, new { htmlAttributes = new { @class = "form-control input-sm" } })
                                            @Html.ValidationMessageFor(model => model.AntiNoiseSettings.MaxConsolidationDelayMinutes, "", new { @class = "text-danger" })

                                            @Html.DescriptionFor(model => model.AntiNoiseSettings.MaxConsolidationDelayMinutes, "help-block", "span")
                                        </div>
                                    </div>
                                </div>
                                <div class="panel-heading">
                                    <h2 class="panel-title">Delivery providers</h2>
                                </div>
                                <div class="panel-body">
                                    @Html.Action("ListDeliveryProviderSettings")
                                </div>


                                <div class="panel-footer">
                                    <div class="">
                                        <button type="submit" class="btn btn-success" tabindex="10"><i class="fa fa-save"></i>&nbsp;&nbsp;Save</button>&nbsp;&nbsp;

                                    </div>
                                </div>
                            </div>

                        }

                    }
                }
            </div>
        </fieldset>
    </div>
</main>